public class TestThress {
  //尝试搞懂动态绑定
  public static void main(String[] args) {
      Animal one = new Cat();
      one.eat();
      Animal two = new Dog();
      two.eat();
      Animal animal = new Animal("圆圆");
      animal.eat();
      //当与不同的子类向上转型时，调用其重写方法，会自动调用该子类的方法
      //而直接使用父类实例化父类的对象时，就只能调用父类自己的对象
  }
}
class Animal{
    public String name;
    public void eat() {
        System.out.println(this.name+"正在吃饭");
    }
    public Animal (String name) {
        this.name = name;
    }
}

class Dog extends Animal{
    public void eat() {
        System.out.println(this.name+"正在吃狗粮");
    }
    public Dog() {
        super("圆圆");
        this.name = "狗";
    }

}

class Cat extends Animal{
    public void eat() {
        System.out.println(this.name+"正在吃猫粮");
    }
    public Cat() {
        super("圆圆");
        this.name = "猫";
    }
}

